- /* slfldiv2.cpp by K.Tsuru */
- // funstion ID = 235 DRADIX, BRADIX
- #ifndef SN_H
- #include "sn.h"
- #endif
- /***************************
- SLong and SInteger calsses
- It divides by 2.
- ****************************/
- SLong LDiv2(const SLong& n){
- SLong result(n);
- uint rh = n.Head(), rt = n.Tail();
- if(rh == 0){ //only one figure including n = 0
- if( (result.figure[0] = n.figure(0)/2) == 0 ) result.SetSign(0);
- return result; // n = 0 or 1
- }
- fType rem = 0, u; // rem : remainder
- fType rdx = n.Radix();
- fType* rv = result.figure.Elements();
-
- #ifndef NDEBUG
- result.figure(rh);
- #endif
-
- for(int i = (int)rh; i >= (int)rt; i--) {
- u = rv[i];
- if(rem) u += rdx;
- rem = u & 1; // rem = 0 or 1
- rv[i] = u / 2;
- }
- if(rem && rt){ rt--; rv[rt] = rdx/2; } // rem = 1
- //get figure positions
- while(!rv[rh]) rh--;
- result.aHead = rh;
- #ifndef NDEBUG
- result.figure(rh);
- #endif
- //[caution] 24 0000....0001 / 2 ===> 12 0000 ... 0000
- while(!rv[rt]) rt++;
- result.aTail = rt;
- return result;
- }
slfldiv2.cpp : last modifiled at 2017/03/13 14:32:00(1,034 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).